#include<bits/stdc++.h>
#define ll long long
#define L xd[x].l
#define R xd[x].r
#define mid (l+r>>1)
#define lc L,l,mid
#define rc R,mid+1,r
#define Root 1,1,n
#define OK l>=Ll&&r<=Rr
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define pb push_back
#define ull unsigned long long
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<int,int>
#define ui unsigned int 
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57) s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(ll x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
const int N =1e5+5,M=4e5+5,inf=2147000000;
const double eps=1e-6;
const ll mod=147744151,llf=1e18;
using namespace std;
int n,k,q,a[N],lsh[N],b[N],m;
int r[N],l[N],s[N],top;
ll ans;
inline int solve(int x){
	if(a[x]==m)return 0;
	int nowr=r[x],nowl=l[x],cnt=0;
	while(1){
		if(a[nowl]>=m&&a[nowr]>=m)return cnt+1;
		cnt++;
		if(a[nowl]==a[nowr])nowl=l[nowl],nowr=r[nowr];
		else if(a[nowl]<a[nowr])nowl=l[nowl];
		else nowr=r[nowr];
	}
}
int main(){
	freopen("summer.in","r",stdin);
	freopen("summer.out","w",stdout);
	n=read(),k=read();
	rep(i,1,n)lsh[i]=a[i]=read();
	sort(lsh+1,lsh+n+1);
	rep(i,2,n+1)if(lsh[i]^lsh[i-1])b[++m]=lsh[i-1];
	rep(i,1,n)a[i]=lower_bound(b+1,b+m+1,a[i])-b;
	a[0]=a[n+1]=inf;
	q=read();
	for(int i=1,x,Ll,Rr;i<=q;i++){
		x=read(),Ll=read(),Rr=read();
		ans=0;
			swap(a[x],a[x+1]);
			rep(j,1,n){
				while(top&&a[s[top]]<a[j])r[s[top--]]=j;
				s[++top]=j;
			}
			while(top)r[s[top--]]=n+1;
			per(j,n,1){
				while(top&&a[s[top]]<a[j])l[s[top--]]=j;
				s[++top]=j;
			}
			while(top)l[s[top--]]=0;
			rep(j,Ll,Rr)ans+=n-1+(ll)k*solve(j);
			pf(ans),putchar('\n');
	}
	return 0;
}
